<?php

namespace App\Models\DylistModels;

use App\Models\ParentModel;
use ClassesWithParents\D;
use DB;
use App\Components\Tools;
use Log;

/**
 * 抖音二次元榜model
 * @author puppet
 */
class DyCospa extends ParentModel
{
    /**
     * 与模型关联的数据表。
     *
     * @var string
     */
    protected $table = 'pt_dy_cospa_overall';

    /**
     * DB::直接操作的数据库表名
     * @var string
     */
    protected $db_table = 'pt_dy_cospa_overall';

    /**
     * 主键 默认id。
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 指定是否模型应该被戳记时间。
     *
     * @var bool
     */
    public $timestamps = false;

    //获取指定的昵称的标题信息
    public function getNicknameinfo($nick)
    {
        $sql = " select title from $this->table where nickname=$nick ";
        $ttitle = DB::select($sql);
        return $ttitle;
    }

    /**
     *    ajax 拉取数据 type 1总榜 2xx榜 获取数据
     * WHERE datediff(day,[dateadd],getdate())=0 查询当天的数据
     */
    function getPageData()
    {
        $time = date('Y-m-d', time());
        $sql = " select * from $this->table where type=1  and TO_DAYS( NOW( ) ) - TO_DAYS( create_time) = 1";
        $sql .= " order by effect_value desc ";//排序以及要的数据
        $res = DB::select($sql);
        // echo '<pre/>'; print_r($res);exit();
        return $res;
    }

    //插入二次元榜数据 视频保存到pt_dy_bangdan_video 共同字段昵称
    function upCospato($date)
    {
        set_time_limit(0);
        foreach ($date as $k => $v) {
            $data = array(
                'rank' => $v['rank'],
                'rank_change' => $v['rank_change'],
                'nickname' => $v['nickname'],
                'avatar' => $v['avatar'],
                'follower_count' => $v['follower_count'],
                'onbillbaord_times' => $v['onbillbaord_times'],
                'create_time' => date('Y-m-d H:i:s', time()),
                'update_time' => date('Y-m-d H:i:s', time()),
                'type' => 1,
                'effect_value' => $v['effect_value'],
            );
            $bid=DB::table($this->table)->insertGetId($data);
            //  echo ''; print_r($bid);
            $vurl=$v['video_list'];
            if(is_array($vurl)){
                foreach ($vurl as $vk=>$vv){
                    $vdata=array(
                        'item_cover' => $vv['item_cover'],
                        'share_url' => $vv['share_url'],
                        'title' => $vv['title'],
                        'bid' => $bid,
                        'create_time' => date('Y-m-d H:i:s', time()),
                        'update_time' => date('Y-m-d H:i:s', time()),
                        'type' =>6,
                    );
                    DB::table("pt_dy_bangdan_video")->insertGetId($vdata);//把榜单视频数据按昵称存入库
                }
            }

        }
    }

}
//            $bid = DB::table($this->table)->insertGetId($data);
//            $vurl = $v['video_list'];
//            //   echo '<pre/>';    print_r($vurl);
//            $sql = " insert into pt_dy_bangdan_video (item_cover,share_url,title,bid,create_time,update_time,type) ";
//            $sql.=" values (?,?,?,?,?,?,?) ";
//            if (is_array($vurl)) {
//                foreach ($vurl as $vk => $vv) {
//                    $vdata = array(
//                        'item_cover' => $vv['item_cover'],
//                        'share_url' => $vv['share_url'],
//                        'title' => $vv['title'],
//                        'bid' => $bid,
//                        'create_time' => date('Y-m-d H:i:s', time()),
//                        'update_time' => date('Y-m-d H:i:s', time()),
//                        'type' => 4,
//                    );
//              //  print_r($vdata);exit();
//                    DB::insert("insert into pt_dy_bangdan_video (item_cover,share_url,title,bid,create_time,update_time,type) values (?,?,?,?,?,?,?)",Array ('item_cover' => "https://p3.douyinpic.com/img/tos-cn-i-0813/0dc2fe8a9fd443bfa987a912e08ab07e~c5_300x400.jpeg?from=2563711402_large",' share_url' => "https://www.iesdouyin.com/share/video/6995510696855293216/?region=CN&mid=6995510785276021535&u_code=0&titleType=title&did=MS4wLjABAAAANwkJuWIRFOzg5uCpDRpMj4OX-QryoDgn-yYlXQnRwQQ&iid=MS4wLjABAAAANwkJuWIRFOzg5uCpDRpMj4OX-QryoDgn-yYlXQnRwQQ&with_sec_did=1", 'title' => "本是平平无奇的打工人，爆发起来竟然如此强#搞笑 #动漫 #轻漫计划 #充能计划", 'bid' => "807 ",'create_time' => "2021-08-12 20:59:04",'update_time'=> "2021-08-12 20:59:04 ",'type' => '4' ));
//                    //  echo '<pre/>';print_r($vdata);
//
//                }
//
//            }
//
//        }
//    }
//
//}